package com.simon.netty.demo2;

import com.simon.netty.demo2.Utils.ByteBufUtils;
import com.simon.netty.demo2.po.Person;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * Created by changf on 2017/7/14.
 */
public class PersonDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        byte[] bytes = ByteBufUtils.ByteBuffToBytes(byteBuf);
        Person person= (Person) ByteBufUtils.byteToObject(bytes);
        list.add(person);
    }
}
